<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Api extends CI_Controller {

    function __construct() {
        parent::__construct();
        $this->load->helper('url');
        $this->load->library('upload');
        $this->load->library('pagination');
        $this->load->library('parser');
        $this->load->helper(array('form', 'url'));
    }

    public function index() {
        redirect('admincp');
    }

    public function cate() {
        $response = array();
        $response["store8x"] = array();
        $lists = $this->app_content->get_cate();
        foreach ($lists as $value) {
            $item = array();
            $item['id'] = $value->id;
            $item['catename'] = $value->catename;
            $item['cateroot'] = $value->cateroot;
            $item['cateimages'] = $value->cateimages;
            $item['active'] = $value->active;
            array_push($response["store8x"], $item);
        }

        echo json_encode($response);
    }

    public function product($cateid=null){
        $response = array();
        $response["store8x"] = array();
        $lists = $this->app_content->get_cate();
        foreach ($lists as $value) {
            $item = array();
            $item['id'] = $value->id;
            $item['catename'] = $value->catename;
            $item['cateroot'] = $value->cateroot;
            $item['cateimages'] = $value->cateimages;
            $item['active'] = $value->active;
            array_push($response["store8x"], $item);
        }
        echo json_encode($response);
    }

    public function sms($userid,$api_id){
    	$this->load->model('app_model');
    	$this->load->model('api_model');
    	$this->load->model('shortcode_model');
    	$shortcodes = $this->shortcode_model->list_shortcode();
    	$response = array();
    	$response["store8x"] = array();
		$datas = $this->api_model->get_api_details($userid,$api_id);
		 foreach ($datas as $data) {
            $item = array();
            $item['id'] = $data->id;

            $item['cuphap'] = 'GKD '.$userid.' '.$api_id;
            $item['tin_tra_ve'] = $data->mess;
            foreach($shortcodes as $shortcode){
	            if($shortcode->id == $data->cost){
	            	$item['dauso'] = $shortcode->shortcode;
	            	$item['gia_tin'] = $shortcode->price;
	            }
            }

            $item['active'] = $data->active;
            array_push($response["store8x"], $item);
        }
        echo json_encode($response);
    }


}

?>